const timeout = (ms) =>
  new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('');
    }, ms);
  });
const ajax1 = () =>
  timeout(2000).then(() => {
    console.log('1');
    return 1;
  });
const ajax2 = () =>
  timeout(1000).then(() => {
    console.log('2');
    return 2;
  });
const ajax3 = () =>
  timeout(500).then(() => {
    console.log('3');
    return 3;
  });
const mergePromise = (ajaxArray) => {
  // 在这里实现你的代码
  let p = Promise.resolve();
  const data = [];
  ajaxArray.forEach(item=>{
    p = p.then(item).then(res=>{
      // res;
      data.push(res);
      return data;
    });
  });
  return p;
};
mergePromise([ajax1, ajax2, ajax3]).then((data) => {
  console.log('done');
  console.log(data); // data 为 [1, 2, 3]
});

// const p = Promise.resolve();
// p.then(res=>{
//    new Promise(resolve=>{
//     setTimeout(()=>{
//       console.log(1);
//       resolve(1);
//       return 1;
//     },1000);// 
//   });
// }).then(res=>{
//    new Promise(resolve=>{
//     setTimeout(()=>{
//       console.log(2);
//       resolve(2);
//     },1000);// 
//   });
// }).then(res=>{
//    new Promise(resolve=>{
//     setTimeout(()=>{
//       console.log(3);
//       resolve(4);
//     },1000);// 
//   });
// });
